package com.wg.msproductgz.controller;
import com.wg.msproductgz.entity.Productspec;
import com.wg.msproductgz.service.ProductspecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProductspecController {
    @Autowired
    private ProductspecService ProductspecService;
    @PostMapping("/product/Productspec/insert")
    public int insert(@RequestBody Productspec Productspec) {
        Boolean result = ProductspecService.save(Productspec);
        return result ? 1 : 0;
    }
    @GetMapping("/product/Productspec/{poductId}")
    public Productspec selectOne(@PathVariable Integer poductId) {
        return ProductspecService.getById(poductId);
    }
    @PostMapping("/product/Productspec")
    public List<Productspec> select(@RequestBody(required = false) Productspec Productspec) {
        try {
            if (Productspec == null) {
                Productspec = new Productspec();
            }
            return ProductspecService.select(Productspec);
        } catch (Exception e) {
            // 记录详细错误信息
            e.printStackTrace();
            throw e;
        }
    }
    @DeleteMapping("/product/Productspec/{poductId}")
    public int delete(@PathVariable Integer poductId) {
        Boolean result = ProductspecService.removeById(poductId);
        return result ? 1 : 0;
    }
    @PutMapping("/product/Productspec")
    public int update(@RequestBody Productspec Productspec) {
        Boolean result = ProductspecService.updateById(Productspec);
        return result ? 1 : 0;
    }
}
